package com.sjd.web.api.mall;

import com.sjd.common.core.controller.BaseController;
import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.page.TableDataInfo;
import com.sjd.mall.domain.dto.shoppingcart.WxShoppingCartAddRequestDTO;
import com.sjd.mall.domain.dto.shoppingcart.WxShoppingCartDeleteRequestDTO;
import com.sjd.mall.domain.dto.shoppingcart.WxShoppingCartQryResponseDTO;
import com.sjd.mall.domain.dto.shoppingcart.WxShoppingCartUpdateRequestDTO;
import com.sjd.mall.service.shoppingcart.WxShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车
 *
 * @author seer
 * @version 1.0
 * @date 2022/1/21 10:05
 */
@Api(tags = "购物车")
@RestController
@RequestMapping(value = "/weixin/api/shoppingCart")
@Slf4j
public class WxShoppingApi extends BaseController {

    @Autowired
    private WxShoppingCartService service;

    /**
     * 购物车添加
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "购物车添加")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody WxShoppingCartAddRequestDTO requestDTO) {
        log.info("购物车添加,请求 {}", requestDTO);
        AjaxResult result = service.add(requestDTO);
        log.info("购物车添加,响应 {}", result);
        return result;
    }

    /**
     * 购物车查询
     *
     * @return object
     */
    @ApiOperation(value = "购物车查询",
            response = WxShoppingCartQryResponseDTO.class)
    @GetMapping("/qry")
    public TableDataInfo qry() {
        startPage();
        List<WxShoppingCartQryResponseDTO> respList = service.qry();
        if (log.isDebugEnabled()) {
            log.debug("购物车查询,响应 {}", respList);
        }
        return getDataTable(respList);
    }

    /**
     * 购物车修改
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "购物车修改")
    @PostMapping("/update")
    public AjaxResult update(@Validated @RequestBody WxShoppingCartUpdateRequestDTO requestDTO) {
        log.info("购物车修改,请求 {}", requestDTO);
        AjaxResult result = service.update(requestDTO);
        log.info("购物车修改,响应 {}", result);
        return result;
    }

    /**
     * 购物车删除
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "购物车删除")
    @PostMapping("/delete")
    public AjaxResult delete(@Validated @RequestBody WxShoppingCartDeleteRequestDTO requestDTO) {
        log.info("购物车删除,请求 {}", requestDTO);
        AjaxResult result = service.delete(requestDTO);
        log.info("购物车删除,响应 {}", result);
        return result;
    }
}
